home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CUCD / Programming / OUI / rcs / eslide.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  29.5 KB  |  1,049 lines

  1. head    1.5;
  2. access;
  3. symbols;
  4. locks
  5.     dlorre:1.5; strict;
  6. comment    @// @;
  7.  
  8.  
  9. 1.5
  10. date    98.01.13.19.56.31;    author dlorre;    state Exp;
  11. branches;
  12. next    1.4;
  13.  
  14. 1.4
  15. date    97.09.17.08.15.38;    author dlorre;    state Exp;
  16. branches;
  17. next    1.3;
  18.  
  19. 1.3
  20. date    97.07.14.04.22.00;    author dlorre;    state Exp;
  21. branches;
  22. next    1.2;
  23.  
  24. 1.2
  25. date    96.08.28.20.00.09;    author dlorre;    state Exp;
  26. branches;
  27. next    1.1;
  28.  
  29. 1.1
  30. date    96.08.22.02.05.10;    author dlorre;    state Exp;
  31. branches;
  32. next    ;
  33.  
  34.  
  35. desc
  36. @Oui.lib -- Object User Interface
  37. Projet créé en 1994
  38. Auteur: Dominique Lorre
  39. @
  40.  
  41.  
  42. 1.5
  43. log
  44. @optimized display
  45. @
  46. text
  47. @// $Id: eslide.cc 1.4 1997/09/17 08:15:38 dlorre Exp dlorre $
  48. #include <graphics/gfxmacros.h>
  49. #include <intuition/classes.h>
  50. #include <intuition/classusr.h>
  51. #include <intuition/gadgetclass.h>
  52. #include <intuition/cghooks.h>
  53. #include <intuition/icclass.h>
  54. #include <utility/tagitem.h>
  55. #include <utility/hooks.h>
  56. #include <libraries/gadtools.h>
  57. #include <stdio.h>
  58. #include <string.h>
  59. #include <mydebug.h>
  60. #include <compiler.h>
  61.  
  62. #include "gadgets/eslide.h"
  63. #include "gadgetlist.h"
  64. #include "window.h"
  65. #include "screen.h"
  66. #include "gadgets/eclass.h"
  67.  
  68. #include <proto/graphics.h>
  69. #include <proto/intuition.h>
  70. #include <proto/utility.h>
  71. #include <clib/alib_protos.h>
  72.  
  73. static Class *BOOPSIeslide ;
  74. static int InitESlide(void) ;
  75. static void FreeESlide(void) ;
  76.  
  77. extern "C" STDARGS ULONG HookEntry() ;
  78.  
  79. // ========================================================================
  80. // ============================  ESLIDE CLASS =============================
  81. // ========================================================================
  82.  
  83.  
  84. eslide::eslide(gadgetlist *gl,
  85.                void (window::*func)(gadget *, unsigned long, unsigned short),
  86.                long min,
  87.                long max,
  88.                long level,
  89.                long freedom,
  90.                const char *t,
  91.                long flags) : gadget(gl, func)
  92. {
  93. int i, l1, l2 ;
  94. BOOL underset = FALSE ;
  95. UWORD *pens = gl->win->ws->drawinfo->dri_Pens;
  96.  
  97.     smin = min ;
  98.     smax = max ;
  99.     cursel = level ;
  100.     disabled = FALSE ;
  101.  
  102.     InitESlide() ;
  103.  
  104.     if (t) {
  105.  
  106.         it1 = new IntuiText ;
  107.         it2 = new IntuiText ;
  108.         it3 = new IntuiText ;
  109.  
  110.         plain = new TTextAttr ;
  111.         underline = new TTextAttr ;
  112.  
  113.         it1->FrontPen = it2->FrontPen = it3->FrontPen =
  114.             pens[(flags&NG_HIGHLABEL)?HIGHLIGHTTEXTPEN:TEXTPEN] ;
  115.         it1->BackPen = it2->BackPen = it3->BackPen = 0 ;
  116.         it1->DrawMode = it2->DrawMode = it3->DrawMode = JAM1 ;
  117.  
  118.         norm1 = new char[strlen(t)+1] ;
  119.         norm2 = new char[strlen(t)+1] ;
  120.         under = new char[2] ;
  121.  
  122.         underkey(t) ;
  123.  
  124.         CopyMem(gl->win->ws->scr->Font, plain, sizeof(struct TTextAttr)) ;
  125.         CopyMem(gl->win->ws->scr->Font, underline, sizeof(struct TTextAttr)) ;
  126.         underline->tta_Style |= FSF_UNDERLINED ;
  127.         font = OpenFont((TextAttr *)underline) ;
  128.  
  129.         for (i=l1=l2=0; t[i]; i++) {
  130.             if (t[i] == '_') {
  131.                 if (t[i+1]) under[0] = t[++i] ;
  132.                 underset = TRUE ;
  133.             }
  134.             else {
  135.                 if (underset) {
  136.                     norm2[l2++] = t[i] ;
  137.                 }
  138.                 else {
  139.                     norm1[l1++] = t[i] ;
  140.                 }
  141.             }
  142.         }
  143.         norm1[l1] = '\0' ;
  144.         norm2[l2] = '\0' ;
  145.         under[1] = '\0' ;
  146.  
  147.         if (l1) {
  148.             it1->IText = (UBYTE *)norm1 ;
  149.             it1->ITextFont = (TextAttr *)plain ;
  150.             if (underset) {
  151.                 it1->NextText = it2 ;
  152.                 it2->LeftEdge = short(IntuiTextLength(it1)) ;
  153.                 it2->IText = (UBYTE *)under ;
  154.                 it2->ITextFont = (TextAttr *)underline ;
  155.                 if (l2) {
  156.                     it2->NextText = it3 ;
  157.                     it3->LeftEdge = short(it2->LeftEdge + IntuiTextLength(it2)) ;
  158.                     it3->IText = (UBYTE *)norm2 ;
  159.                     it3->ITextFont = (TextAttr *)plain ;
  160.                 }
  161.             }
  162.         }
  163.         else if (underset) {
  164.             it1->IText = (UBYTE *)under ;
  165.             it1->ITextFont = (TextAttr *)underline ;
  166.             it1->NextText = it2 ;
  167.             it2->LeftEdge = short(IntuiTextLength(it1)) ;
  168.             it2->IText = (UBYTE *)norm2 ;
  169.             it2->ITextFont = (TextAttr *)plain ;
  170.         }
  171.     }
  172.     gad = gl->gad  = (Gadget *)NewObject(BOOPSIeslide, NULL,
  173.             GA_ID,              gl->ng->ng_GadgetID,
  174.             GA_Top,             gl->ng->ng_TopEdge,
  175.             GA_Left,            gl->ng->ng_LeftEdge,
  176.             GA_Width,           gl->ng->ng_Width,
  177.             GA_Height,          gl->ng->ng_Height,
  178.  
  179.             GA_Immediate,       TRUE,
  180.             GA_Previous,        gl->gad,
  181.             GA_RelVerify,       TRUE,
  182.  
  183.             GA_UserData,        EGA_Level,
  184.             PGA_Freedom,        freedom,
  185.             GA_IntuiText,       it1 ,
  186.  
  187.             EGA_Min,            min,
  188.             EGA_Max,            max,
  189.             EGA_Flags,          flags,
  190.             EGA_Level,          level,
  191.             EGA_TextAttr,       gl->ng->ng_TextAttr,
  192.             EGA_XPens,          gl->win->ws->xpens,
  193.             EGA_GPen,           gl->gpen,
  194.  
  195.             TAG_DONE);
  196.  
  197. }
  198.  
  199. eslide::~eslide()
  200. {
  201.     if (norm1) delete norm1 ;
  202.     if (norm2) delete norm2 ;
  203.     if (under) delete under ;
  204.  
  205.     if (it1) delete it1 ;
  206.     if (it2) delete it2 ;
  207.     if (it3) delete it3 ;
  208.  
  209.     if (plain) delete plain ;
  210.     if (underline) delete underline ;
  211.  
  212.     if (gad) DisposeObject(gad) ;
  213.     if (font) CloseFont(font) ;
  214.     FreeESlide() ;
  215. }
  216.  
  217. void eslide::set(long level, long min, long max, short disable)
  218. {
  219.     if (((level == -1) || (cursel == level)) && ((min == -1) || (smin == min))
  220.         && ((max == -1) ||(max == smax)) && (disable == disabled)) {
  221.         // nothing to do
  222.         return ;
  223.     }
  224.  
  225.     if (min != -1) smin = min ;
  226.     if (max != -1) smax = max ;
  227.     if (cursel != -1) cursel = level ;
  228.     disabled = disable ;
  229.  
  230.     SetGadgetAttrs(gad, w, NULL,
  231.         (level != -1)?EGA_Level:TAG_IGNORE,  level,
  232.         (min != -1)?EGA_Min:TAG_IGNORE,      min,
  233.         (max != -1)?EGA_Max:TAG_IGNORE,      max,
  234.         GA_Disabled,                        disable,
  235.         TAG_END) ;
  236. }
  237.  
  238. void eslide::action(unsigned long classe, unsigned short code)
  239. {
  240.     if (classe != IDCMP_GADGETDOWN) {
  241.         cursel = code ;
  242.         gadget::action(classe, code) ;
  243.     }
  244. }
  245.  
  246. void eslide::keystroke(BOOL shifted)
  247. {
  248.     if (shifted) {
  249.         cursel-- ;
  250.         if (cursel < smin) cursel= smax ;
  251.     }
  252.     else {
  253.         cursel++ ;
  254.         if (cursel > smax)
  255.             cursel = smin ;
  256.     }
  257.     SetGadgetAttrs(gad, w, NULL,
  258.         EGA_Level,  cursel,
  259.         TAG_END) ;
  260.     gadget::action(NULL, cursel) ;
  261. }
  262.  
  263.  
  264.  
  265. // ========================================================================
  266. // =============================== ESLIDE =================================
  267. // ========================================================================
  268.  
  269. struct SlideINST {
  270.     long        Min ;       // limits and level values
  271.     long        Max ;
  272.     long        Level ;
  273.     long        Total ;
  274.  
  275.     long        Top ;
  276.     long        DTop ;
  277.     long        PTop ;      // Previous Top
  278.  
  279.     long        GLeft ;     // Gadget coordinates
  280.     long        GTop ;
  281.     long        GWidth ;
  282.     long        GHeight ;
  283.  
  284.     long        KLeft ;     // Knob coordinates
  285.     long        KTop ;
  286.     long        KWidth ;
  287.     long        KHeight ;
  288.     long        KRight ;
  289.     long        KBottom ;
  290.  
  291.     long        Orient ;     // indicates the orientation (HORIZ or VERT)
  292.     long        Flags ;     // the NewGadget Flags
  293.  
  294.     BOOL        KnobHit ;   // User is moving the Knob
  295.     BOOL        RedrawAll ; // Complete Refresh
  296.     BOOL        Disabled ;  // for redraw check
  297.     BOOL        Direction ;
  298.  
  299.     TextAttr    *TAttr ;  // How to display the level value
  300.     TextFont    *Font ;
  301.     IntuiText   *IText ;
  302.  
  303.     UWORD       *XPens ;    // rendering information
  304.     UWORD       GPen ;
  305. } ;
  306.  
  307. static ULONG STDARGS dispatchESlide(Class *cl, Object *o, Msg msg);
  308.  
  309. static void    NotifySlide(Class *, Object *, ULONG, long, gpInput *) ;
  310.  
  311. static ULONG   RenderESlide(Class *, Gadget *, gpRender *) ;
  312.  
  313. static void    SlideLims(SlideINST *inst, Gadget *g, GadgetInfo *gi) ;
  314.  
  315.  
  316.  
  317. static unsigned short ditherData[2] = {0x5555,0xAAAA};
  318. static int ESlideCnt = 0 ;
  319. int InitESlide(void)
  320. {
  321.     if (ESlideCnt) {
  322.         ESlideCnt++ ;
  323.     }
  324.     else if (!(BOOPSIeslide = MakeClass(NULL, (UBYTE *)"gadgetclass", NULL,
  325.         sizeof(SlideINST), 0))) {
  326.         ESlideCnt = 0 ;
  327.     }
  328.     else {
  329.         BOOPSIeslide->cl_Dispatcher.h_Entry = (HOOKFUNC)HookEntry ;
  330.         BOOPSIeslide->cl_Dispatcher.h_SubEntry = (HOOKFUNC)dispatchESlide;
  331.         BOOPSIeslide->cl_Dispatcher.h_Data = NULL ;
  332.         ESlideCnt = 1 ;
  333.     }
  334.     return ESlideCnt ;
  335. }
  336.  
  337. void FreeESlide(void)
  338. {
  339.     ESlideCnt-- ;
  340.     if (!ESlideCnt)
  341.         FreeClass(BOOPSIeslide) ;
  342. }
  343.  
  344. ULONG SAVEDS STDARGS dispatchESlide(Class *cl, Object *o, Msg msg)
  345. {
  346. SlideINST *inst ;
  347. ULONG retval = FALSE ;
  348. Object *object ;
  349.  
  350.     GETA4 ;
  351.     if (msg->MethodID != OM_NEW)
  352.         inst = (SlideINST *)INST_DATA(cl, o) ;
  353.     switch (msg->MethodID) {
  354.     case OM_NEW:
  355.         if (object = (Object *)DoSuperMethodA(cl, o, msg)) {
  356.             inst = (SlideINST *)INST_DATA(cl, object) ;
  357.             inst->KnobHit = FALSE ;
  358.             inst->Min = (long)GetTagData(EGA_Min, 0, ((opSet *)msg)->ops_AttrList) ;
  359.             inst->Max = (long)GetTagData(EGA_Max, 15, ((opSet *)msg)->ops_AttrList) ;
  360.             inst->Level = (long)GetTagData(EGA_Level, 0, ((opSet *)msg)->ops_AttrList) ;
  361.             inst->Total = inst->Max - inst->Min + 1 ;
  362.             inst->TAttr = (TextAttr *)GetTagData(EGA_TextAttr, 0, ((opSet *)msg)->ops_AttrList) ;
  363.             inst->XPens = (UWORD *)GetTagData(EGA_XPens, NULL, ((opSet *)msg)->ops_AttrList) ;
  364.             inst->GPen = (UWORD)GetTagData(EGA_GPen, NULL, ((opSet *)msg)->ops_AttrList) ;
  365.             inst->Orient = (long)GetTagData(PGA_Freedom, LORIENT_HORIZ, ((opSet *)msg)->ops_AttrList) ;
  366.             inst->IText = (IntuiText *)GetTagData(GA_IntuiText,
  367.                 NULL,
  368.                 ((opSet *)msg)->ops_AttrList) ;
  369.             inst->Flags = (LONG)GetTagData(EGA_Flags, PLACETEXT_LEFT,
  370.                     ((opSet *)msg)->ops_AttrList) ;
  371.  
  372.             if (inst->TAttr)
  373.                 inst->Font = OpenFont(inst->TAttr) ;
  374.             else
  375.                 inst->Font = NULL ;
  376.             inst->Top = inst->Level - inst->Min ;
  377.             inst->RedrawAll = TRUE ;
  378.             retval = (ULONG)object ;
  379.         }
  380.         break ;
  381.     case OM_DISPOSE:
  382.         CloseFont(inst->Font) ;
  383.         retval = DoSuperMethodA(cl, o, msg) ;
  384.         break ;
  385.     case GM_GOACTIVE:
  386.         {
  387.         gpInput *gpi = (gpInput *)msg ;
  388.             if (gpi->gpi_IEvent) {
  389.                 ((Gadget *)o)->Flags |= GFLG_SELECTED ;
  390.                 inst->RedrawAll = FALSE ;
  391.  
  392.                 // is the mouse inside the knob ?
  393.                 if (((gpi->gpi_Mouse.X + inst->GLeft) >= inst->KLeft) &&
  394.                     ((gpi->gpi_Mouse.X + inst->GLeft) <= inst->KRight) &&
  395.                     ((gpi->gpi_Mouse.Y + inst->GTop) >= inst->KTop) &&
  396.                     ((gpi->gpi_Mouse.Y + inst->GTop) <= inst->KBottom)) {
  397.                         inst->KnobHit = TRUE ;
  398.                         inst->Direction = TRUE ;
  399.                         if (inst->Orient & LORIENT_HORIZ)
  400.                             inst->DTop = (gpi->gpi_Mouse.X * inst->Total) / inst->GWidth - inst->Top ;
  401.                         else
  402.                             inst->DTop = ( inst->Total - (gpi->gpi_Mouse.Y * inst->Total) / inst->GHeight) - inst->Top ;
  403.                 }
  404.                 else {
  405.                     inst->Direction = FALSE ;
  406.                     if (inst->Orient & LORIENT_HORIZ) {
  407.                         if ((gpi->gpi_Mouse.X + inst->GLeft)<= inst->KLeft)
  408.                             inst->Top-- ;
  409.                         else
  410.                             inst->Top++ ;
  411.                     }
  412.                     else {
  413.                         if ((gpi->gpi_Mouse.Y + inst->GTop)<= inst->KTop)
  414.                             inst->Top++ ;
  415.                         else
  416.                             inst->Top-- ;
  417.                     }
  418.                 }
  419.                 retval = GMR_MEACTIVE ;
  420.                 RenderESlide(cl, (Gadget *)o, (gpRender *)msg) ;
  421.                 NotifySlide(cl, o, OPUF_INTERIM, inst->Level, gpi) ;
  422.                 *(gpi->gpi_Termination) = inst->Level ;
  423.         }
  424.         else
  425.             retval = GMR_NOREUSE ;
  426.         }
  427.         break ;
  428.     case GM_RENDER:
  429.         inst->RedrawAll = BOOL(((gpRender *)msg)->gpr_Redraw == GREDRAW_REDRAW) ;
  430.         retval = RenderESlide(cl, (Gadget *)o, (gpRender *)msg) ;
  431.         break ;
  432.     case GM_HANDLEINPUT:
  433.         {
  434.             gpInput *gpi = (gpInput *)msg ;
  435.             InputEvent *ie = gpi->gpi_IEvent ;
  436.  
  437.             inst->PTop = inst->Top ;
  438.             retval = GMR_MEACTIVE ;
  439.  
  440.             if (ie->ie_Class == IECLASS_RAWMOUSE) {
  441.                 switch (ie->ie_Code) {
  442.                     case SELECTUP:
  443.                         if (((gpi->gpi_Mouse).X < inst->GLeft) ||
  444.                            ((gpi->gpi_Mouse).X > inst->GLeft + inst->GWidth) ||
  445.                            ((gpi->gpi_Mouse).Y < inst->GTop) ||
  446.                            ((gpi->gpi_Mouse).Y > inst->GTop + inst->GHeight) ) {
  447.                                 *(gpi->gpi_Termination) = inst->Level ;
  448.                                 retval = GMR_NOREUSE | GMR_VERIFY ;
  449.                         }
  450.                         else
  451.                             retval = GMR_NOREUSE ;
  452.                         break ;
  453.                     case MENUDOWN:
  454.                         retval = GMR_REUSE ;
  455.                         NotifySlide(cl, o, 0, inst->Level, (gpInput *)msg) ;
  456.                         break ;
  457.                     default:
  458.                         retval = GMR_MEACTIVE ;
  459.                 }
  460.             }
  461.             else if (ie->ie_Class == IECLASS_TIMER && inst->Direction) {
  462.                 if (inst->Orient & LORIENT_HORIZ)
  463.                     inst->Top = ((gpi->gpi_Mouse.X) * inst->Total) /
  464.                         inst->GWidth - inst->DTop ;
  465.                 else
  466.                     inst->Top = (inst->Total-((gpi->gpi_Mouse.Y) * inst->Total) /
  467.                         inst->GHeight) - inst->DTop ;
  468.  
  469.                 if (inst->PTop != inst->Top) {
  470.                     inst->RedrawAll = FALSE ;
  471.                     RenderESlide(cl, (Gadget *)o, (gpRender *)msg) ;
  472.                     NotifySlide(cl, o, OPUF_INTERIM, inst->Level, gpi) ;
  473.                 }
  474.             }
  475.         }
  476.         break ;
  477.     case GM_GOINACTIVE:
  478.         ((Gadget *)o)-> Flags &= ~GFLG_SELECTED ;
  479.         inst->KnobHit = FALSE ;
  480.         inst->RedrawAll = FALSE ;
  481.         RenderESlide(cl, (Gadget *)o, (gpRender *)msg) ;
  482.         break ;
  483.     case OM_GET:
  484.         switch (((opGet *)msg)->opg_AttrID) {
  485.         case EGA_Min:
  486.             retval = inst->Min ;
  487.             break ;
  488.         case EGA_Max:
  489.             retval = inst->Max ;
  490.             break ;
  491.         case EGA_Level:
  492.             retval = inst->Level ;
  493.             break ;
  494.         default:
  495.             retval = DoSuperMethodA(cl, o, msg) ;
  496.         }
  497.         break ;
  498.     case OM_SET:
  499.         retval = DoSuperMethodA(cl, o, msg) ;
  500.         if ( FindTagItem(EGA_Min, ((opSet *)msg)->ops_AttrList) ||
  501.             FindTagItem(EGA_Max, ((opSet *)msg)->ops_AttrList) ||
  502.             FindTagItem(EGA_Level, ((opSet *)msg)->ops_AttrList) ) {
  503.             RastPort *rp ;
  504.             Gadget *g  = (Gadget *)o ;
  505.             LONG    redraw ;
  506.  
  507.             inst->Min = (long)GetTagData(EGA_Min, inst->Min, ((opSet *)msg)->ops_AttrList) ;
  508.             inst->Max = (long)GetTagData(EGA_Max, inst->Max, ((opSet *)msg)->ops_AttrList) ;
  509.             inst->Level = (long)GetTagData(EGA_Level, inst->Level, ((opSet *)msg)->ops_AttrList) ;
  510.             inst->Total = inst->Max - inst->Min + 1 ;
  511.             inst->Top = inst->Level - inst->Min ;
  512.             redraw = (inst->Disabled ^ (g->Flags & GFLG_DISABLED)) ? GREDRAW_REDRAW : GREDRAW_UPDATE ;
  513.             inst->Disabled = g->Flags & GFLG_DISABLED ;
  514.  
  515.             if (rp = ObtainGIRPort( ((opSet *)msg)->ops_GInfo) ) {
  516.                 DoMethod(o, GM_RENDER, ((opSet *)msg)->ops_GInfo, rp, redraw) ;
  517.                 ReleaseGIRPort(rp) ;
  518.             }
  519.         }
  520.         break ;
  521.     default :
  522.         retval = DoSuperMethodA(cl, o, msg) ;
  523.         break ;
  524.     }
  525.     return retval ;
  526. }
  527.  
  528.  
  529. void SAVEDS NotifySlide(Class *cl, Object *o, ULONG flags, long level, gpInput *gpi)
  530. {
  531. static TagItem tt[3] ;
  532.  
  533.     GETA4 ;
  534.     tt[0].ti_Tag = EGA_Level ;
  535.     tt[0].ti_Data = level  ;
  536.  
  537.     tt[1].ti_Tag = GA_ID ;
  538.     tt[1].ti_Data = ((Gadget *)o)->GadgetID ;
  539.  
  540.     tt[2].ti_Tag = TAG_DONE ;
  541.  
  542.     DoSuperMethod(cl, o, OM_NOTIFY, tt, gpi->gpi_GInfo, flags) ;
  543. }
  544.  
  545. ULONG SAVEDS RenderESlide(Class *cl, Gadget *g, gpRender *msg)
  546. {
  547. RastPort    *rp ;
  548. ULONG       retval = TRUE ;
  549. UWORD       *pens = msg->gpr_GInfo->gi_DrInfo->dri_Pens ;
  550. SlideINST   *inst = (SlideINST *)INST_DATA(cl, (Object *)g) ;
  551. char        kbuf[8] ;
  552. WORD        ls ;
  553. LONG        l, t, len ; // left, top, len utilisés pour l'affichage
  554. IntuiText   *itext ;    // affichage du label
  555.  
  556.     GETA4 ;
  557.     if (msg->MethodID == GM_RENDER)
  558.         rp = msg->gpr_RPort ;
  559.     else
  560.         rp = ObtainGIRPort(msg->gpr_GInfo) ;
  561.     if (rp) {
  562.         SetAPen(rp, pens[SHADOWPEN]) ;
  563.         SetDrMd(rp, JAM1) ;
  564.         SetFont(rp, inst->Font) ;
  565.  
  566.         WaitTOF() ;
  567.         if (g->Flags & GFLG_DISABLED) {
  568.             SlideLims(inst, g, msg->gpr_GInfo) ;
  569.             SetAPen(rp, pens[BACKGROUNDPEN]) ;
  570.             RectFill(rp,
  571.                 inst->GLeft,
  572.                 inst->GTop,
  573.                 inst->GLeft+inst->GWidth,
  574.                 inst->GTop+inst->GHeight) ;
  575.             goto out ;
  576.         }
  577.         else if (inst->RedrawAll) {
  578.             SlideLims(inst, g, msg->gpr_GInfo) ;
  579.             SetAPen(rp, inst->XPens[GFILL_PEN]) ;
  580.             RectFill(rp,
  581.                 inst->GLeft,
  582.                 inst->GTop,
  583.                 inst->GLeft+inst->GWidth-1,
  584.                 inst->GTop+inst->GHeight-1) ;
  585.  
  586.             SetAPen(rp, pens[SHINEPEN]) ;
  587.  
  588.             Move(rp, inst->GLeft+1, inst->GTop+inst->GHeight-1) ;
  589.             Draw(rp, inst->GLeft+1, inst->GTop+1) ;
  590.             Draw(rp, inst->GLeft+inst->GWidth-1, inst->GTop+1) ;
  591.             Draw(rp, inst->GLeft+inst->GWidth-1, inst->GTop+inst->GHeight-1) ;
  592.             Draw(rp, inst->GLeft+1, inst->GTop+inst->GHeight-1) ;
  593.  
  594.             SetAPen(rp, pens[SHADOWPEN]) ;
  595.  
  596.             Move(rp, inst->GLeft, inst->GTop) ;
  597.             Draw(rp, inst->GLeft+inst->GWidth-2, inst->GTop) ;
  598.             Draw(rp, inst->GLeft+inst->GWidth-2, inst->GTop+inst->GHeight-2) ;
  599.             Draw(rp, inst->GLeft, inst->GTop+inst->GHeight-2) ;
  600.             Draw(rp, inst->GLeft, inst->GTop) ;
  601.             if (inst->IText) {  // Le gadget possède un label
  602.                 itext = inst->IText ;
  603.  
  604.                 // recherche du dernier itext pour la longueur
  605.  
  606.                 while (itext->NextText) itext = itext->NextText ;
  607.  
  608.                 // Le calcul par défaut est pour PLACETEXT_IN
  609.  
  610.                 len = IntuiTextLength(itext) + itext->LeftEdge ;
  611.                 t = inst->GTop + 1 +
  612.                     (inst->GHeight - itext->ITextFont->ta_YSize -2) / 2 ;
  613.                 l = inst->GLeft + 1 + (inst->GWidth - len - 2) / 2 ;
  614.  
  615.  
  616.                 if (inst->Flags & PLACETEXT_RIGHT) {
  617.                     l = inst->GLeft + inst->GWidth + 4 ;
  618.                 }
  619.                 else if (inst->Flags & PLACETEXT_ABOVE) {
  620.                     t = inst->GTop - itext->ITextFont->ta_YSize - 4 ;
  621.                 }
  622.                 else if (inst->Flags & PLACETEXT_BELOW) {
  623.                     t = inst->GTop + inst->GHeight + 4 ;
  624.                 }
  625.                 else if (!(inst->Flags & PLACETEXT_IN)) {  // PLACETEXT_LEFT
  626.                     l = inst->GLeft - len - 4 ;
  627.                 }
  628.                 PrintIText(rp, inst->IText, l, t) ;
  629.             }
  630.         }
  631.         else {
  632.             SetAPen(rp, inst->XPens[GFILL_PEN]) ;
  633.             RectFill(rp,
  634.                 inst->KLeft,
  635.                 inst->KTop,
  636.                 inst->KRight,
  637.                 inst->KBottom) ;
  638.             SlideLims(inst, g, msg->gpr_GInfo) ;
  639.         }
  640.         SetAPen(rp, pens[FILLPEN]) ;
  641.  
  642.         SetAfPt(rp, ditherData, 1) ;
  643.         RectFill(rp, inst->KLeft,
  644.                      inst->KTop,
  645.                      inst->KRight,
  646.                      inst->KBottom ) ;
  647.  
  648.         SetAfPt(rp, NULL, 0 ) ; // Fin du tramage
  649.  
  650.         SetAPen(rp, pens[(g->Flags & GFLG_SELECTED)?SHADOWPEN:SHINEPEN]) ;
  651.  
  652.         Move(rp, inst->KLeft+1, inst->KBottom) ;
  653.         Draw(rp, inst->KLeft+1, inst->KTop+1) ;
  654.         Draw(rp, inst->KRight, inst->KTop+1) ;
  655.         Draw(rp, inst->KRight, inst->KBottom) ;
  656.         Draw(rp, inst->KLeft+1, inst->KBottom) ;
  657.  
  658.         SetAPen(rp, pens[(g->Flags & GFLG_SELECTED)?SHINEPEN:SHADOWPEN]) ;
  659.  
  660.         Move(rp, inst->KLeft, inst->KTop) ;
  661.         Draw(rp, inst->KRight-1, inst->KTop) ;
  662.         Draw(rp, inst->KRight-1, inst->KBottom-1) ;
  663.         Draw(rp, inst->KLeft, inst->KBottom-1) ;
  664.         Draw(rp, inst->KLeft, inst->KTop) ;
  665.  
  666.         SetAPen(rp, (g->Flags & GFLG_SELECTED) ? pens[HIGHLIGHTTEXTPEN] :
  667.                     inst->GPen) ;
  668.  
  669.  
  670.         sprintf(kbuf, "%ld", inst->Level) ;
  671.         ls = strlen(kbuf) ;
  672.         Move(   rp,
  673.                 inst->KLeft+(inst->KWidth - TextLength(rp, kbuf, ls))/2,
  674.                 inst->KTop+(inst->KHeight-rp->TxHeight)/2+rp->TxBaseline ) ;
  675.  
  676.         Text(rp, kbuf, ls) ;
  677.  
  678. out:
  679.         if (msg->MethodID != GM_RENDER)
  680.             ReleaseGIRPort(rp) ;
  681.  
  682.     }
  683.     else
  684.         retval = FALSE ;
  685.     return retval ;
  686. }
  687.  
  688.  
  689. void SAVEDS SlideLims(SlideINST *inst, Gadget *g, GadgetInfo *gi)
  690. {
  691.  
  692.     GETA4 ;
  693.     // we must not go outside the limits
  694.  
  695.     if (inst->Top < 0)
  696.         inst->Top = 0 ;
  697.     else if (inst->Top >= inst->Total)
  698.         inst->Top = inst->Total - 1 ;
  699.  
  700.     inst->Level = inst->Top + inst->Min ;
  701.  
  702.     inst->GLeft = g->LeftEdge ;
  703.     inst->GTop = g->TopEdge ;
  704.     inst->GWidth = g->Width  ;
  705.     inst->GHeight = g->Height ;
  706.  
  707.     if (inst->Orient & LORIENT_HORIZ) {
  708.         inst->KTop = inst->GTop + 2 ;
  709.         inst->KHeight = inst->GHeight - 4 ;
  710.  
  711.         inst->KWidth = 40 ;
  712.         if (inst->Total > 1) {
  713.             inst->KLeft = g->LeftEdge + 2 +
  714.             ((inst->GWidth-inst->KWidth-4) * inst->Top) / (inst->Total-1) ;
  715.         }
  716.         else
  717.             inst->KLeft = g->LeftEdge+2 ;
  718.  
  719.     }
  720.     else {
  721.         inst->KLeft = inst->GLeft + 2 ;
  722.         inst->KHeight = inst->TAttr->ta_YSize+4 ;
  723.  
  724.         if (inst->Total > 1) {
  725.             inst->KTop = g->TopEdge + 2 + ((inst->GHeight-inst->KHeight-4) *
  726.                 (inst->Total-inst->Top)) / (inst->Total-1) ;
  727.         }
  728.         else
  729.             inst->KTop = g->TopEdge + 2 ;
  730.  
  731.         inst->KWidth = inst->GWidth-4 ;
  732.  
  733.     }
  734.     inst->KRight = inst->KLeft + inst->KWidth - 1 ;
  735.     inst->KBottom = inst->KTop + inst->KHeight - 1 ;
  736.  
  737. }
  738.  
  739.  
  740. @
  741.  
  742.  
  743. 1.4
  744. log
  745. @*** empty log message ***
  746. @
  747. text
  748. @d1 1
  749. a1 1
  750. // $Id: eslide.cc 1.3 1997/07/14 04:22:00 dlorre Exp dlorre $
  751. d54 1
  752. d173 10
  753. a182 3
  754.     smin = min ;
  755.     smax = max ;
  756.     cursel = level ;
  757. d250 1
  758. d305 2
  759. a335 1
  760.         inst = (SlideINST *)INST_DATA(cl, o) ;
  761. a341 1
  762.             inst = (SlideINST *)INST_DATA(cl, o) ;
  763. d383 1
  764. a390 1
  765.             inst = (SlideINST *)INST_DATA(cl, o) ;
  766. a432 1
  767.         inst = (SlideINST *)INST_DATA(cl, o) ;
  768. a437 1
  769.         inst = (SlideINST *)INST_DATA(cl, o) ;
  770. d459 1
  771. a460 1
  772.             inst = (SlideINST *)INST_DATA(cl, o) ;
  773. d466 2
  774. a467 1
  775.             SlideLims(inst, g, ((opSet *)msg)->ops_GInfo) ;
  776. d470 1
  777. a470 2
  778.                 inst->RedrawAll = TRUE ;
  779.                 DoMethod(o, GM_RENDER, ((opSet *)msg)->ops_GInfo, rp, GREDRAW_REDRAW) ;
  780. d522 1
  781. d667 1
  782. a667 1
  783.             inst->KLeft = g->LeftEdge + 2 + 
  784. d679 1
  785. a679 1
  786.             inst->KTop = g->TopEdge + 2 + ((inst->GHeight-inst->KHeight-4) * 
  787. @
  788.  
  789.  
  790. 1.3
  791. log
  792. @*** empty log message ***
  793. @
  794. text
  795. @d1 1
  796. a1 1
  797. // $Id: eslide.cc 1.2 1996/08/28 20:00:09 dlorre Exp dlorre $
  798. d658 6
  799. a663 2
  800.         inst->KLeft = g->LeftEdge + 2 + ((inst->GWidth-inst->KWidth-4) * inst->Top) /
  801.             (inst->Total-1) ;
  802. d670 6
  803. a675 2
  804.         inst->KTop = g->TopEdge + 2 + ((inst->GHeight-inst->KHeight-4) * (inst->Total-inst->Top)) /
  805.             (inst->Total-1) ;
  806. @
  807.  
  808.  
  809. 1.2
  810. log
  811. @changement look + support sliders verticaux
  812. @
  813. text
  814. @d1 1
  815. a1 1
  816. // $Id$
  817. d13 2
  818. d22 4
  819. a25 17
  820. #include <cxxproto/graphics.h>
  821. #include <cxxproto/intuition.h>
  822.  
  823. extern "C"
  824. {
  825. extern struct Library *UtilityBase ;
  826. struct TagItem *FindTagItem( Tag tagVal, struct TagItem *tagList );
  827. ULONG GetTagData( Tag tagValue, unsigned long defaultVal,
  828.         struct TagItem *tagList );
  829. #include <pragmas/utility_pragmas.h>
  830.  
  831. ULONG DoMethod( Object *obj, unsigned long MethodID, ... );
  832. ULONG DoSuperMethodA( struct IClass *cl, Object *obj, Msg message );
  833. ULONG DoSuperMethod( struct IClass *cl, Object *obj, unsigned long MethodID,
  834.         ... );
  835. }
  836.  
  837. d31 2
  838. d42 9
  839. a50 2
  840.                long level, long freedom) : gadget(gl, func)
  841. {
  842. d57 68
  843. d138 1
  844. d142 1
  845. d154 13
  846. a166 1
  847.     DisposeObject(gad) ;
  848. d237 2
  849. a238 1
  850.     long        Flags ;     // indicates the orientation (HORIZ or VERT)
  851. d244 1
  852. a244 1
  853.     TextAttr    *TextAttr ; // How to display the level value
  854. d246 1
  855. d252 1
  856. a252 2
  857. static ULONG __asm dispatchESlide(register __a0 Class *cl,
  858.     register __a2 Object *o, register __a1 Msg msg);
  859. d269 1
  860. a269 1
  861.     else if (!(BOOPSIeslide = MakeClass(NULL, "gadgetclass", NULL,
  862. d274 3
  863. a276 1
  864.         BOOPSIeslide->cl_Dispatcher.h_Entry = (HOOKFUNC)dispatchESlide;
  865. d289 1
  866. a289 3
  867. ULONG __saveds __asm dispatchESlide(register __a0 Class *cl,
  868.                            register __a2 Object *o,
  869.                            register __a1 Msg msg)
  870. d294 2
  871. d305 1
  872. a305 1
  873.             inst->TextAttr = (TextAttr *)GetTagData(EGA_TextAttr, 0, ((opSet *)msg)->ops_AttrList) ;
  874. d308 6
  875. a313 1
  876.             inst->Flags = (long)GetTagData(PGA_Freedom, LORIENT_HORIZ, ((opSet *)msg)->ops_AttrList) ;
  877. d315 2
  878. a316 2
  879.             if (inst->TextAttr)
  880.                 inst->Font = OpenFont(inst->TextAttr) ;
  881. d344 4
  882. a347 1
  883.                         inst->DTop = (gpi->gpi_Mouse.X * inst->Total) / inst->GWidth - inst->Top ;
  884. d351 1
  885. a351 1
  886.                     if (inst->Flags & LORIENT_HORIZ) {
  887. d359 2
  888. a361 2
  889.                         else
  890.                             inst->Top++ ;
  891. d407 1
  892. a407 1
  893.                 if (inst->Flags & LORIENT_HORIZ)
  894. d411 2
  895. a412 2
  896.                     inst->Top = ((gpi->gpi_Mouse.Y) * inst->Total) /
  897.                         inst->GHeight - inst->DTop ;
  898. d476 1
  899. a476 1
  900. void __saveds NotifySlide(Class *cl, Object *o, ULONG flags, long level, gpInput *gpi)
  901. d480 1
  902. d492 1
  903. a492 1
  904. ULONG __saveds RenderESlide(Class *cl, Gadget *g, gpRender *msg)
  905. d500 2
  906. d503 1
  907. d519 2
  908. a520 2
  909.                 inst->GLeft+inst->GWidth-1,
  910.                 inst->GTop+inst->GHeight-1) ;
  911. d536 3
  912. a538 3
  913.             Draw(rp, inst->GLeft+inst->GWidth, inst->GTop+1) ;
  914.             Draw(rp, inst->GLeft+inst->GWidth, inst->GTop+inst->GHeight) ;
  915.             Draw(rp, inst->GLeft, inst->GTop+inst->GHeight) ;
  916. d543 3
  917. a545 3
  918.             Draw(rp, inst->GLeft+inst->GWidth-1, inst->GTop) ;
  919.             Draw(rp, inst->GLeft+inst->GWidth-1, inst->GTop+inst->GHeight-1) ;
  920.             Draw(rp, inst->GLeft, inst->GTop+inst->GHeight-1) ;
  921. d547 29
  922. d598 1
  923. a598 1
  924.         Move(rp, inst->KLeft+1, inst->KTop+inst->KHeight-1) ;
  925. d600 3
  926. a602 3
  927.         Draw(rp, inst->KLeft+inst->KWidth, inst->KTop+1) ;
  928.         Draw(rp, inst->KLeft+inst->KWidth, inst->KTop+inst->KHeight) ;
  929.         Draw(rp, inst->KLeft, inst->KTop+inst->KHeight) ;
  930. d607 3
  931. a609 3
  932.         Draw(rp, inst->KLeft+inst->KWidth-1, inst->KTop) ;
  933.         Draw(rp, inst->KLeft+inst->KWidth-1, inst->KTop+inst->KHeight-1) ;
  934.         Draw(rp, inst->KLeft, inst->KTop+inst->KHeight-1) ;
  935. d635 1
  936. a635 1
  937. void __saveds SlideLims(SlideINST *inst, Gadget *g, GadgetInfo *gi)
  938. d638 1
  939. d653 1
  940. a653 1
  941.     if (inst->Flags & LORIENT_HORIZ) {
  942. d664 1
  943. a664 1
  944.         inst->KHeight = inst->TextAttr->ta_YSize+4 ;
  945. d666 1
  946. a666 1
  947.         inst->KTop = g->TopEdge + 2 + ((inst->GHeight-inst->KHeight-4) * inst->Top) /
  948. d672 2
  949. a673 2
  950.     inst->KRight = inst->KLeft + inst->KWidth ;
  951.     inst->KBottom = inst->KTop + inst->KHeight ;
  952. @
  953.  
  954.  
  955. 1.1
  956. log
  957. @Initial revision
  958. @
  959. text
  960. @d1 1
  961. d51 1
  962. a51 1
  963.                long level) : gadget(gl, func)
  964. d71 1
  965. d136 1
  966. a136 1
  967.     long        Min ;
  968. d139 1
  969. a140 1
  970.     long        Total ;
  971. d143 1
  972. a143 1
  973.     long        PTop ;
  974. d145 1
  975. a145 1
  976.     long        GLeft ;
  977. d150 1
  978. a150 1
  979.     long        KLeft ;
  980. d157 4
  981. a160 2
  982.     BOOL        KnobHit ;
  983.     BOOL        RedrawAll ;
  984. d162 2
  985. a163 1
  986.     TextAttr    *TextAttr ;
  987. d165 2
  988. a166 1
  989.     UWORD       *XPens ;
  990. d225 2
  991. d248 2
  992. d260 12
  993. a271 4
  994.                     if ((gpi->gpi_Mouse.X + inst->GLeft)<= inst->KLeft)
  995.                         inst->Top-- ;
  996.                     else
  997.                         inst->Top++ ;
  998. d316 7
  999. a322 1
  1000.                 inst->Top = ((gpi->gpi_Mouse.X) * inst->Total) / inst->GWidth - inst->DTop ;
  1001. d324 1
  1002. d335 1
  1003. a335 1
  1004.         inst->RedrawAll = TRUE ;
  1005. d371 1
  1006. a371 1
  1007.  
  1008. d438 12
  1009. a449 1
  1010.             Move(rp, inst->GLeft+inst->GWidth-1, inst->GTop+inst->GHeight-1) ;
  1011. d472 1
  1012. a472 9
  1013.         SetAPen(rp, pens[TEXTPEN]) ;
  1014.  
  1015.         Move(rp, inst->KLeft-1, inst->GTop+1) ;
  1016.         Draw(rp, inst->GLeft+1, inst->GTop+1) ;
  1017.         Draw(rp, inst->GLeft+1, inst->GTop+inst->GHeight-2) ;
  1018.         Draw(rp, inst->KLeft-1, inst->GTop+inst->GHeight-2) ;
  1019.  
  1020.         Move(rp, inst->KLeft, inst->KTop+1) ;
  1021.         Draw(rp, inst->KLeft, inst->KBottom-1) ;
  1022. d474 13
  1023. a486 4
  1024.         Move(rp, inst->KRight+1, inst->GTop+1) ;
  1025.         Draw(rp, inst->GLeft+inst->GWidth-2, inst->GTop+1) ;
  1026.         Draw(rp, inst->GLeft+inst->GWidth-2, inst->GTop+inst->GHeight-2) ;
  1027.         Draw(rp, inst->KRight+1, inst->GTop+inst->GHeight-2) ;
  1028. d488 2
  1029. a489 2
  1030.         Move(rp, inst->KRight, inst->KTop+1) ;
  1031.         Draw(rp, inst->KRight, inst->KBottom-1) ;
  1032. a491 2
  1033.         SetAPen(rp, inst->GPen) ;
  1034.  
  1035. d514 2
  1036. d528 7
  1037. a534 2
  1038.     inst->KTop = inst->GTop + 1 ;
  1039.     inst->KHeight = inst->GHeight - 2 ;
  1040. d536 7
  1041. a542 2
  1042.     inst->KLeft = g->LeftEdge + 1 + ((inst->GWidth-42) * inst->Top) / (inst->Total-1) ;
  1043.     inst->KWidth = 40 ;
  1044. d544 5
  1045. a548 2
  1046.     inst->KRight = inst->KLeft + inst->KWidth - 1;
  1047.     inst->KBottom = inst->KTop + inst->KHeight - 1 ;
  1048. @
  1049.